package com.kailong.controller.sys;

import com.kailong.annotation.ExcelExport;
import com.kailong.annotation.NoLogin;
import com.kailong.dto.sys.MenuTreeDTO;
import com.kailong.entity.ResponsePageEntity;
import com.kailong.entity.sys.MenuConditionEntity;
import com.kailong.entity.sys.MenuEntity;
import com.kailong.enums.ExcelBizTypeEnum;
import com.kailong.service.sys.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * created by kailong on 2025/8/8
 */


@Tag(name = "菜单操作", description = "菜单接口")
@RestController
@RequestMapping("/v1/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;;
    @NoLogin
    @Operation(summary = "获取菜单树", description = "获取菜单树")
    @GetMapping("/getMenuTree")
    public  List<MenuTreeDTO> getMenuTree() {
        return menuService.getMenuTree();
    }
    /**
     * 批量删除菜单
     *
     * @param ids 菜单ID
     * @return 影响行数
     */
    @NoLogin
    @Operation(summary = "删除菜单", description = "删除菜单")
    @PostMapping("/deleteByIds")
    public int deleteByIds(@RequestBody @NotNull List<Long> ids) {
        return menuService.deleteByIds(ids);
    }
    /**
     * 根据条件查询菜单列表
     *
     * @param menuConditionEntity 条件
     * @return 菜单列表
     */
    @NoLogin
    @Operation(summary = "根据条件查询菜单列表", description = "根据条件查询菜单列表")
    @PostMapping("/searchByPage")
    public ResponsePageEntity<MenuEntity> searchByPage(@RequestBody MenuConditionEntity menuConditionEntity) {
        return menuService.searchByPage(menuConditionEntity);
    }
    @NoLogin
    @ExcelExport(ExcelBizTypeEnum.MENU)
    @Operation(summary = "导出菜单数据", description = "导出菜单数据")
    @PostMapping("/export")
    public void export(MenuConditionEntity menuConditionEntity) throws IOException {

    }
    @NoLogin
    @Operation(summary = "新增菜单", description = "新增菜单")
    @PostMapping("/insert")
    public int insert(@RequestBody MenuEntity menuEntity) {
        return menuService.insert(menuEntity);
    }
    @NoLogin
    @Operation(summary = "更新菜单", description = "更新菜单")
    @PostMapping("/update")
    public int update(@RequestBody MenuEntity menuEntity) {
        return menuService.update(menuEntity);
    }

}
